﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class AnimatorStateInvoke : MonoBehaviour
{
    public AnimatorState animatorState;
    public string targetState;
    public UnityEvent invoke;
    public bool update;
    bool isInvoke = false;

    // Update is called once per frame
    void Update()
    {
        if ((!isInvoke || update) && animatorState.state == targetState)
        {
            invoke?.Invoke();
            isInvoke = true;
        }
    }

    private void OnEnable()
    {
        isInvoke = false;
    }
}
